package com.dinnerwithfriends.client.authentication.google;

import com.dinnerwithfriends.client.GWTEntryPoint;
import com.dinnerwithfriends.client.dinner.invite.CreateDinner;
import com.dinnerwithfriends.client.dinner.invite.DinnerConfirmation;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;



/** 
 * 
 * 
 * @
 * @Feature 
 */
public class GoogleAuthentication extends VerticalPanel {

	public GoogleAuthentication() {

		GoogleLoginServiceAsync loginService = GWT
				.create(GoogleLoginService.class);

		loginService.login(GWT.getHostPageBaseURL(),
				new AsyncCallback<GoogleLoginInfo>() {

					public void onFailure(Throwable error) {
					}

					public void onSuccess(GoogleLoginInfo result) {

						GWTEntryPoint.loginInfo = result;

						if (GWTEntryPoint.loginInfo.isLoggedIn()) {

							new CreateDinner();

							DinnerConfirmation.buttonLogout
									.setHTML(GWTEntryPoint.loginInfo
											.getLogoutUrl());

						} else {

							GoogleSignInButton.signInLink
									.setHref(GWTEntryPoint.loginInfo
											.getLoginUrl());
						}
					}
				});
	}
}
